home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4402 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  28 lines

  1. Newsgroups: comp.lang.c++
  2. Path: atom.ansto.gov.au!teslab!andrew
  3. From: andrew@teslab.lab.oz.au (Andrew Phillips)
  4. Subject: How to handle error in constructor
  5. Organization: Technology Services, Research, Sydney
  6. Date: Tue, 30 Jan 1996 00:54:21 GMT
  7. Message-ID: <DLyyIM.5EG@teslab.lab.oz.au>
  8. X-Newsreader: TIN [version 1.2 PL0]
  9.  
  10. I'm converting and enhancing a simple program in C to C++.  Without going
  11. into too much detail I have a class that represents a file on disk.  The
  12. contructor opens the file, but what should it do if the file cannot be
  13. opened?  The C program just calls fopen() tests the return value and 
  14. if there's an error it prints a message and exits.
  15.  
  16. In C++ I thought to set a flag in the constructor and have a member function
  17. that tests the flag to see if the file was opened correctly.  This seems
  18. rather inelegant -- I guess exceptions would be the elegant way but seem
  19. like overkill for such a simple program.  I've looked in several C++ books but
  20. error handling is given scant coverage except for exception handling.
  21.  
  22. Any suggestions would be greatly appreciated.
  23.  
  24. -- 
  25. Andrew Phillips (News/Sys Admin)  andrew@teslab.lab.oz.au  +61 2 287 6551
  26. --------------------------------
  27. Just a SPOKE, not a SPOKESPERSON
  28.